package model

import (
	"gorm.io/gorm"
	"time"
	"video_08_28/global"
)

type UserInfo struct {
	Id        uint32         `gorm:"column:id;type:int UNSIGNED;comment:用户主页ID;primaryKey;not null;" form:"id" json:"id"`            // 用户主页ID
	UserId    int32          `gorm:"column:user_id;type:int;comment:用户ID;not null;" form:"user_id" json:"user_id"`                   // 用户ID
	Name      string         `gorm:"column:name;type:varchar(20);comment:昵称;not null;" form:"name" json:"name"`                      // 昵称
	Info      string         `gorm:"column:info;type:varchar(60);comment:签名;not null;" form:"info" json:"info"`                      // 签名
	LikeNum   int32          `gorm:"column:like_num;type:int;comment:粉丝数;not null;default:0;" form:"like_num" json:"like_num"`       // 粉丝数
	FollowNum int32          `gorm:"column:follow_num;type:int;comment:关注数;not null;default:0;" form:"follow_num" json:"follow_num"` // 关注数
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" form:"created_at" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" form:"updated_at" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" form:"deleted_at" json:"deleted_at"`
}

func (i *UserInfo) TableName() string {
	return "user_info"
}

func (i *UserInfo) FindInfo() error {
	return global.DB.Where("user_id = ?", i.UserId).Find(&i).Error
}

func (i *UserInfo) AddInfo() error {
	return global.DB.Create(&i).Error
}

func (i *UserInfo) UpdatedInfo() error {
	return global.DB.Updates(&i).Error
}
